import React from 'react';
import styles from './Correlate.less';
import { Table, Tooltip, Popconfirm } from 'antd';
import moment from 'moment';

const CorrelateList = (props) => {

  const { correlateType, correlateList, userLoading, rowSelection, currentPage, pageSize } = props;

  let targetName = null, subjectName = null;
  if (correlateType == "0") {
    targetName = "角色", subjectName = "用户";
  } else if (correlateType == "1") {
    targetName = "岗位", subjectName = "用户";
  } else if (correlateType == "2") {
    targetName = "租户", subjectName = "应用";
  } else if (correlateType == "3") {
    targetName = "单位", subjectName = "部门";
  } else if (correlateType == "4") {
    targetName = "部门", subjectName = "岗位";
  } else if (correlateType == "6") {
    targetName = "应用", subjectName = "角色";
  }

  const columns = [
    { title: '序号', width: '10%', render: (text, record, index) => <span>{(index + 1) + (currentPage - 1) * pageSize}</span> },
    { title: targetName + "名称", dataIndex: 'targetName', key: 'targetName', width: '30%' },
    { title: subjectName + '名称', dataIndex: 'subjectName', key: 'subjectName', width: '30%' },
    { title: '创建时间', dataIndex: 'createTime', key: 'createTime', width: '20%',
      render: (text, record, index) => {
        const createTime = text ? text.replace("T", " ") : "";
        const result = moment(createTime).format("YYYY-MM-DD");
        return <span>{result}</span>;
      }
    }
  ];

  return (
    <div className={ styles.listTable }>
      <Table
        bordered
        tableLayout={"auto"}
        rowSelection={rowSelection}
        columns={columns}
        dataSource={correlateList}
        pagination={false}
        loading={userLoading}
        rowKey={record => record.id}
        scroll={{y: (window.innerHeight - 230)}}
      />
    </div>
  );
};

export default CorrelateList;
